#ifndef MACROBLOCK_H
#define MACROBLOCK_H
#include <stdint.h>
#include "common.h"

enum macroblock_position_e
{
    MB_LEFT     = 0x01,
    MB_TOP      = 0x02,
    MB_TOPRIGHT = 0x04,
    MB_TOPLEFT  = 0x08,

    MB_PRIVATE  = 0x10,

    ALL_NEIGHBORS = 0xf,
};

// 宏块邻居信息结构体
typedef struct macro_block_neighbors_info_s{
    uint32_t i_neighbour;
    int i_mb_type_top;
    int i_mb_type_left;
    int i_mb_type_topleft;
    int i_mb_type_topright;

} macro_block_neighbors_info_t;

typedef enum 
{
    I_4x4           = 0,
    I_8x8           = 1,
    I_16x16         = 2,
    I_PCM           = 3,

    P_L0            = 4,
    P_8x8           = 5,
    P_SKIP          = 6,

    B_DIRECT        = 7,
    B_L0_L0         = 8,
    B_L0_L1         = 9,
    B_L0_BI         = 10,
    B_L1_L0         = 11,
    B_L1_L1         = 12,
    B_L1_BI         = 13,
    B_BI_L0         = 14,
    B_BI_L1         = 15,
    B_BI_BI         = 16,
    B_8x8           = 17,
    B_SKIP          = 18,

    X264_MBTYPE_MAX = 19
}mb_class_e;

typedef struct {
    uint8_t non_zero_count[16 * 3];
}mb_cache;

typedef struct macro_block_s
{
    int     i_last_qp;      // 上一个qp
    int     i_last_dqp; /* last delta qp */
    int     field_decoding_flag;

    int     i_mb_width;
    int     i_mb_height;
    int     i_mb_count;

    picture_t pic;
    macro_block_neighbors_info_t neighbors;
    mb_class_e type;
    int     i_intra16x16_pred_mode;
    int     i_chroma_pred_mode;
    int     i_qp;
    int     i_cbp_luma;
    int     i_cbp_chroma;
    mb_cache cache;
}macro_block_t;

#endif